package com.jbyu.utils;

public class OrmUtil {
	
	public static String firstToUpperCase(String string){
		
		if(null==string) return null;
		if("".equals(string))return "";
		return string.substring(0,1).toUpperCase()+string.substring(1);
	}
	
	
	public static String convertString_ByUpper(String temp){
		if(null==temp) return null;
		if("".equals(temp))return "";
		temp=temp.replace("tb_ttp_", "").replace("TB_TTP_", "");
		StringBuffer bf=new StringBuffer();
		int next=0;
        while (temp.indexOf("_")!=-1) {
			int index=temp.indexOf("_");
			int end =index+1;
			bf.append(temp.substring(next, index));
			temp=firstToUpperCase(temp.substring(end));
		}
        if(temp!=null)
        bf.append(temp);
        return bf.toString();
	}
	
	public static String convertString_ByUpper(String temp,String replace_set){
		if(null==temp) return null;
		if("".equals(temp))return "";
		temp=temp.replace(replace_set.toLowerCase(), "").replace(replace_set.toUpperCase(), "");
		StringBuffer bf=new StringBuffer();
		int next=0;
        while (temp.indexOf("_")!=-1) {
			int index=temp.indexOf("_");
			int end =index+1;
			bf.append(temp.substring(next, index));
			temp=firstToUpperCase(temp.substring(end));
		}
        if(temp!=null)
        bf.append(temp);
        return bf.toString();
	}
	public static String firstToLowerCase(String string){
		
		if(null==string) return null;
		if("".equals(string))return "";
		return string.substring(0,1).toLowerCase()+string.substring(1);
	}
	
	
	public  static String getSetString(String string){
		
		return "set"+firstToUpperCase(string.toLowerCase());
	}
	
	public static String getGetString(String string){
		
		return "get"+firstToUpperCase(string.toLowerCase());
	}

	public static String ifNullIsEmpty(String str){
		if(str==null){
			return "";
		}
		return str;
	}

	
	public static void main(String[] args) {
		String temp="8989asdfasdf_adsfa";
		StringBuffer bf=new StringBuffer();
		int next=0;
        while (temp.indexOf("_")!=-1) {
			int index=temp.indexOf("_");
			int end =index+1;
			bf.append(temp.substring(next, index));
			temp=firstToUpperCase(temp.substring(end));
		}
        if(temp!=null)
        bf.append(temp);
	}
}
